<template>
	<view class="navbar">
		<view class="con" :style="{background: type == 2 ? 'transparent' : '#FFFFFF'}">
			<view class="status-bar" :style="{height: statusBarHeight+'px'}"></view>
			<view class="nav-bar-title" :style="{height: navigationBarHeight+'px'}">
				<view class="title" v-if="type == 1">{{title}}</view>
				<view class="title2" v-if="type == 2">{{title}}</view>
				<view class="title3" v-if="type == 3">
					<view class="title3-icon">
						<navigator open-type="navigateBack">
							<u-icon name="arrow-left" color="#191E2F" size="28"></u-icon>
						</navigator>
						
						<view class="line"></view>
						<navigator url="/pages/index/index" open-type="switchTab">
							<image src="@/static/icon/nav_bar_home.png"></image>
						</navigator>
					</view>

					<view class="text">{{title}}</view>
					<view :style="{width: customWidth + 'px', height: '1px'}"></view>
				</view>
			</view>
		</view>
		<view class="con-height" :style="{height: navHeight + 'px'}"></view>
	</view>
</template>

<script>
	const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
	// #ifdef MP-WEIXIN
	// 获取微信胶囊的位置信息 width,height,top,right,left,bottom
	const custom = wx.getMenuButtonBoundingClientRect();
	// console.log(custom)
	const customWidth = custom.width;

	// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
	const navigationBarHeight = custom.height + (custom.top - statusBarHeight) * 2;
	// console.log("导航栏高度："+this.globalData.navigationBarHeight)

	// 总体高度 = 状态栏高度 + 导航栏高度
	const navHeight = navigationBarHeight + statusBarHeight;

	// #endif
	export default {
		name: 'nav-bar-title',
		props: {
			//标题
			title: String,

			// 样式
			type: {
				type: Number,
				default: 1,
			},
		},

		data() {
			return {
				statusBarHeight: statusBarHeight,
				navigationBarHeight: navigationBarHeight,
				navHeight: navHeight,
				customWidth: customWidth,
			}
		},
		created() {

		},
		methods: {

		},
	}
</script>

<style lang="scss" scoped>
	.navbar {

		.con {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			width: 100%;
			background: #FFFFFF;

			.nav-bar-title {
				display: flex;
				align-items: center;

				.title {
					font-size: 40rpx;
					font-weight: 800;
					color: #333333;
					padding-left: 38rpx;
				}

				.title2 {
					width: 100%;
					text-align: center;
					font-size: 36rpx;
					font-weight: 600;
					color: #FFFFFF;
					font-family: 'PingFangSC-Semibold, PingFang SC';
				}

				.title3 {
					width: 100%;
					display: flex;
					align-items: center;

					.title3-icon {
						width: 164rpx;
						height: 56rpx;
						border-radius: 28rpx;
						border: 2rpx solid #8F949C;
						display: flex;
						align-items: center;
						justify-content: center;
						margin-left: 28rpx;
						
						image {
							width: 32rpx;
							height: 32rpx;
						}

						.line {
							width: 2rpx;
							height: 34rpx;
							background: #8F949C;
							margin: 0 20rpx 0 30rpx;
						}
					}


					.text {
						flex: 1;
						text-align: center;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						margin: 0 20rpx;
						font-size: 36rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666660;
					}
				}

			}
		}
	}
</style>
